package collector.storage;

import collector.data.Currency;
import collector.data.Stock;
import collector.data.StockList;
import collector.data.StockMarket;
import collector.support.Collector;

public abstract class DataStorage {
	public void includeCollector(Collector collector) {
		for (StockMarket stockMarket : collector) {
			includeMarket(stockMarket);
			for (StockList stockList : stockMarket) {
				includeList(stockList,stockMarket);
				for (Stock stock : stockList) {
					includeStock(stock,stockList);
				}
			}
		}
	}

	protected abstract boolean marketExists(StockMarket market);

	protected abstract void addMarket(StockMarket market);

	public void includeMarket(StockMarket market) {
		if (!marketExists(market))
			addMarket(market);
	}

	protected abstract boolean listExists(StockMarket market, StockList stockList);

	public void includeList(StockList stockList, StockMarket market) {
		if (!listExists(market, stockList))
			addList(stockList, market);
	}

	protected abstract void addList(StockList stockList, StockMarket market);

	protected abstract boolean stockExists(Stock stock, StockList stockList);

	protected abstract void addStock(Stock stock, StockList stockList);

	protected abstract void updateStock(Stock stock, StockList stockList);

	public void includeStock(Stock stock, StockList stockList) {
		if (stockExists(stock,stockList))
			updateStock(stock,stockList);
		else
			addStock(stock,stockList);
	}

	protected abstract boolean currencyExists(Currency currency);

	protected abstract void updateCurrency(Currency currency);

	protected void includeCurrency(Currency currency) {
		if (currencyExists(currency))
			updateCurrency(currency);
		else
			addCurrency(currency);
	}
	
	protected abstract void addCurrency(Currency currency);
}